export function init() {
  // currentFa.label = undefined
  currentObj = JSON.parse(JSON.stringify(currentTemp))
  subCurrentObj = JSON.parse(JSON.stringify(subCurrentObj))
}

export function setFavalue(data) {
  currentFa = data
}

export function setCurrentvalue(data) {
  currentObj = data
}
export function setSubTable() {
  // 找到更新, 没找到新增
  for (let v of currentObj.sublist) {
    if (v.apltable == subCurrentObj.apltable) {
      v = JSON.parse(JSON.stringify(subCurrentObj))
      console.log('更新从表', v)
      return
    }
  }
  console.log('新增从表', subCurrentObj)
  currentObj.sublist.push(JSON.parse(JSON.stringify(subCurrentObj)))
}
export function setSubCurrentObj(data) {
  subCurrentObj = data
}

export function setTreeList(data) {
  // console.log('setTreeList', data)
  treeList = data
}

export let treeList = []

export let currentFa = {
  label: undefined,
  data: currentObj
}
// 当前配置项
export let currentObj = {
  apltable: undefined,
  enttable: undefined,
  label: undefined,
  relationfield: undefined, // 申请表关联字段
  entrelationfield: undefined, // 企业表关联字段
  primary: undefined, // 显示字段
  isappend: false, // 同步补正
  toplevel: false, // 是否顶级
  isaddown: false, // 是否添加允许自己
  span: 2, // 一行几个
  maprelation: {},
  require: true,
  rules: {},
  fieldlist: [
    //   {
    //   t: undefined,
    //   b: undefined,
    //   isRequired: true,
    //   islabel: false,
    //   hidden: false,
    //   disable: false,
    //   default: undefined,
    //   type: undefined,
    //   option: {
    //   }
    // }
  ],
  children: [],
  sublist: []
}

// 从表配置项
export let subCurrentObj = {
  apltable: undefined,
  enttable: undefined,
  label: undefined,
  relationfield: undefined,
  maprelation: {},
  require: true,
  rules: {},
  fieldlist: [{
    t: undefined,
    b: undefined,
    isRequired: true,
    islabel: false,
    hidden: false,
    disable: false,
    default: undefined,
    type: undefined,
    option: {}
  }]
}



// Temp配置项
export let currentTemp = {
  apltable: undefined,
  enttable: undefined,
  label: undefined,
  relationfield: undefined, // 申请表关联字段
  entrelationfield: undefined, // 企业表关联字段
  primary: undefined, // 显示字段
  isappend: false, // 同步补正
  toplevel: false, // 是否顶级
  isaddown: false, // 是否添加允许自己
  span: 2, // 一行几个
  maprelation: {},
  require: true,
  rules: {},
  fieldlist: [
    //   {
    //   t: undefined,
    //   b: undefined,
    //   isRequired: true,
    //   islabel: false,
    //   hidden: false,
    //   disable: false,
    //   default: undefined,
    //   type: undefined,
    //   option: {
    //   }
    // }
  ],
  children: [],
  sublist: []
}

// Temp配置项
export let subCurrentTemp = {
  apltable: undefined,
  enttable: undefined,
  label: undefined,
  relationfield: undefined,
  maprelation: {},
  require: true,
  rules: {},
  fieldlist: [{
    t: undefined,
    b: undefined,
    isRequired: true,
    islabel: false,
    hidden: false,
    disable: false,
    default: undefined,
    type: undefined,
    option: {}
  }]
}